package com.huo.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.huo.constant.MessageConstant;
import com.huo.entity.Result;
import com.huo.pojo.Setmeal;
import com.huo.service.SetmealService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Description: 套餐控制层
 * @Author: 汪青松
 * @CreateDate: 2021/2/10 22:22
 */
@RestController
@RequestMapping("/setmeal")
public class SetmealController {

    @Reference
    private SetmealService setmealService;

    /**
     * @Description: 获取套餐列表
     * @Author: 汪青松
     * @Param: []
     * @Return: com.huo.entity.Result
     * @CreateDate: 2021/2/10 22:23
     */
    @RequestMapping("/getAllSetmeal")
    public Result getAllSetmeal() {
        try {
            List<Setmeal> setmealList = setmealService.getAllSetmeal();
            return new Result(true, MessageConstant.QUERY_SETMEALLIST_SUCCESS, setmealList);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.QUERY_SETMEALLIST_FAIL);
        }
    }

    /**
     * @Description: 根据id查找套餐信息
     * @Author: 汪青松
     * @Param: [id]
     * @Return: com.huo.entity.Result
     * @CreateDate: 2021/2/15 13:48
     */
    @RequestMapping("/findById")
    public Result findById(@RequestParam Integer id) {
        try {
            Setmeal setmeal = setmealService.findById(id);
            return new Result(true, MessageConstant.QUERY_SETMEAL_SUCCESS, setmeal);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.QUERY_SETMEAL_FAIL);
        }
    }
}
